package com.shynin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shynin.common.bean.dto.UserDTO;
import com.shynin.entity.TUser;
import com.shynin.service.ITUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shynin
 * @since 2019-01-29
 */
@RestController
@RequestMapping("/user")
public class TUserController {
    @Autowired
    private ITUserService itUserService;

    @GetMapping("/id/{id}")
    public UserDTO fetchUserById(@PathVariable("id") Long id) {
        TUser user = itUserService.getById(id);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(user, userDTO);
        return userDTO;
    }

    @GetMapping("/name/{name}")
    public UserDTO fetchUserByName(@PathVariable("name") String name) {
        TUser user = itUserService.getOne(new QueryWrapper<TUser>().eq("username",name));
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(user, userDTO);
        return userDTO;
    }

}
